package com.dhl.single;

/**
 * @title: 饿汉式静态常量
 * @Author danghailiang
 * @Date: 2022/7/26 20:25
 * @Version 1.0
 */
public class 饿汉式静态常量 {
    public static void main(String[] args) {
        SingleStaticConst instance = SingleStaticConst.getInstance();
        SingleStaticConst instance1 = SingleStaticConst.getInstance();
        System.out.println(instance == instance1);
    }
}

class SingleStaticConst {
    /**
     * 构造器私有化
     */
    private SingleStaticConst() {

    }

    /**
     * 实例化对象
     */
    private static SingleStaticConst instance = new SingleStaticConst();

    /**
     * 返回对象
     */
    public static SingleStaticConst getInstance() {
        return instance;
    }
}
